interface REFS {
}

interface INP {
    success: (cap) => void;
}

const viewId = 'uploaderList' + webix.uid();

@YvanUI.BizModule()
export default class UploadDialog extends YvanUI.BaseDialog<UploadDialog, REFS, INP> {

    uploadArray: any;

    viewResolver(): any {
        return {
            title: `上传文件`,
            modal: false,
            width: 550,
            height: 400,
            body: {
                padding: 0,
                rows: [
                    {
                        view:"form",
                        rows: [
                            {
                                view: "uploader",
                                value: '上传图片',
                                name:"files",
                                accept:"image/png, image/gif, image/jpg",
                                link:viewId,
                                // upload:"/!/grid/GridService@uploadImage",
                                upload: '/upload',
                                on: {
                                    onFileUpload: this.onFileUpload
                                }
                            },
                            {
                                view:"list",
                                id:viewId,
                                type:"uploader",
                                height: 220,
                            },
                        ]
                    },
                    {},
                    {
                        view:"form",
                        cols: [
                            {},
                            {
                                view: 'button',
                                text: "确定",
                                icon: "fa fa-bars",
                                onClick: {
                                    type: "function",
                                    bind: "okClick",
                                },
                            }
                        ]
                    },
                ]
            }
        };
    }

    onFileUpload(param: any) {
        const { data } = param;
        this.uploadArray.push(data);
    }

    onLoad() {
        this.uploadArray = []
    }

    okClick() {
        this.inParamter.success(this.uploadArray);
        this.closeDialog();
    }
}